// pages/chexian/shopping/shopping.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		carid:'',
		xsz: '',
		http: getApp().globalData.map,
		sfzz:'',
		sfzf:"",
		yyzz:'',
		bao:['投保','不投保'],
		disanf:['10万','15万','20万','30万','50万','150万','200万','250万','300万',
		'350万','400万','500万','550万','600万','650万','700万','750万','800万','850万','900万','950万','1000万','不投保'],
		jiashi:['1万','2万','3万','4万','5万','10万','15万','20万','不投保'],
		huahen:['2000','5000','1万','2万','5万','不投保'],
		time:'',
		time1:'',
		time2:'',
		time3:'',
		time4:'',
		time5:'',
		time6:'',
		time7:'',
		time8:'',
		time9:'',
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		// 、购买保险
		//     参数名：action=AddBaoxian, uid=用户ID，carid=车辆ID，
		// carNo=车牌号，jqxtime=交强险时间，syxtime=商业险时间，Chesunxian=车损险，
		// Sanzexian=三者险，Sijizrx=司机险，Huahengx=划痕险，Chengkzrx=乘客险，Fadongjix=发动机特殊险，
		// jrx=节假日翻倍险，Addnewsbx=新增设备险[{“sbname”:设备名称,” price”:购买金额,” addTime”:购买时间}]，,
		// jqx=交强险，CardNoz=身份证正面照，
		// CardNoF=身份证反面照，Xingsz=行驶证照，yyzz=营业执照
	},
	onShow(){
		wx.getStorage({
			key:'uid',
			success:(e)=>{
				this.setData({
					uid:e.data.uid
				})
			},fail:(e)=>{
				wx.navigateTo({
					url:'../../register/register'
				})
			}
		})
		wx.getStorage({
			key:'car',
			success:(e)=>{
				console.log(e)
				this.setData({
					carid:e.data[0].ID
				})
			}
		})
		wx.getStorage({
			key:'peijian',
			success:(e)=>{
				this.setData({
					list:e.data
				})
			}
		})
	},
	none(e) {
		if (e.currentTarget.dataset.id == 0) {
			this.setData({
				xsz: ''
			})
		}else if(e.currentTarget.dataset.id == 1){
			this.setData({
				sfzz: ''
			})
		}else if(e.currentTarget.dataset.id == 2){
			this.setData({
				sfzf: ''
			})
		}else if(e.currentTarget.dataset.id == 3){
			this.setData({
				yyzz: ''
			})
		}
	},
	bindTimeChange: function(e) {
		this.setData({
			time: e.detail.value
		})
	},
	bindTimeChange1: function(e) {
		this.setData({
			time1: e.detail.value
		})
	},
	bindTimeChange2: function(e) {
		this.setData({
			time2: this.data.bao[e.detail.value]
		})
	},
	bindTimeChange3: function(e) {
		this.setData({
			time3: this.data.disanf[e.detail.value]
		})
	},
	bindTimeChange4: function(e) {
		this.setData({
			time4:this.data.jiashi[e.detail.value]
		})
	},
	bindTimeChange5: function(e) {
		this.setData({
			time5:this.data.jiashi[e.detail.value]
		})
	},
	bindTimeChange6: function(e) {
		this.setData({
			time6:this.data.huahen[e.detail.value]
		})
	},
	bindTimeChange7: function(e) {
		this.setData({
			time7:this.data.bao[e.detail.value]
		})
	},
	bindTimeChange8: function(e) {
		this.setData({
			time8:this.data.bao[e.detail.value]
		})
	},
	bindTimeChange9: function(e) {
		this.setData({
			time9:this.data.bao[e.detail.value]
		})
	},
	xsz(e) {
		let that = this
		wx.chooseImage({
			count: 1,
			sizeType: 'compressed',
			success: (e) => {
				wx.uploadFile({
					url: getApp().globalData.http3,
					filePath: e.tempFilePaths[0],
					name: 'picturePath',
					success: function(res) {
						let a = JSON.parse(res.data)
						console.log(a)
						that.setData({
							xsz: a.data.headImage
						})
					},
				})
			}
		})
	},
	sfzz(e) {
		let that = this
		wx.chooseImage({
			count: 1,
			sizeType: 'compressed',
			success: (e) => {
				wx.uploadFile({
					url: getApp().globalData.http3,
					filePath: e.tempFilePaths[0],
					name: 'picturePath',
					success: function(res) {
						let a = JSON.parse(res.data)
						console.log(a)
						that.setData({
							sfzz: a.data.headImage
						})
					},
				})
			}
		})
	},
	sfzf(e) {
		let that = this
		wx.chooseImage({
			count: 1,
			sizeType: 'compressed',
			success: (e) => {
				wx.uploadFile({
					url: getApp().globalData.http3,
					filePath: e.tempFilePaths[0],
					name: 'picturePath',
					success: function(res) {
						let a = JSON.parse(res.data)
						console.log(a)
						that.setData({
							sfzf: a.data.headImage
						})
					},
				})
			}
		})
	},
	yyzz(e) {
		let that = this
		wx.chooseImage({
			count: 1,
			sizeType: 'compressed',
			success: (e) => {
				wx.uploadFile({
					url: getApp().globalData.http3,
					filePath: e.tempFilePaths[0],
					name: 'picturePath',
					success: function(res) {
						let a = JSON.parse(res.data)
						console.log(a)
						that.setData({
							yyzz: a.data.headImage
						})
					},
				})
			}
		})
	},
	btn(){
		let a=this.data.list
		let b=JSON.stringify(a);
		wx.request({
			url:getApp().globalData.http+'action=AddBaoxian&uid='+this.data.uid+'&carid='+this.data.carid+'&carNo='
			+this.data.pai+'&jqxtime='+this.data.time+'&syxtime='+this.data.time1+'&Chesunxian='+this.data.time2+
			'&Sanzexian='+this.data.time3+'&Sijizrx='+this.data.time4+'&Chengkzrx='+this.data.time5+'&Huahengx='+
			this.data.time6+'&jrx='+this.data.time7+'&Fadongjix='+this.data.time8+'&jqx='+this.data.time9+'&CardNoF='
			+this.data.sfzf+'&Xingsz='+this.data.xsz+'&CardNoz='+this.data.sfzz+
			'&yyzz='+this.data.yyzz+'&Addnewsbx='+b,
			success: (e) => {
				console.log(e)
				if(e.data.code==1){
					wx.showToast({
						title:e.data.msg,
						icon:'none'
					})
					wx.navigateBack({
						delta:1
					})
				}else{
					wx.showToast({
						title:e.data.msg,
						icon:'none'
					})
				}
			}
		})
	},
	pai(e){
		this.setData({
			pai:e.detail.value
		})
	}
})
